define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Receipt, $window, $timeout,GoPage,GoDialog) {
		
		$scope.init_data = function(){
			Receipt.invoice_list(function(data){
				$scope.datas = data.invoice;
//				$timeout(function() {
//					Swiper('.swiper-container', {
//						slidesPerView: 3,
//						spaceBetween: 0,
//						freeMode: true
//					});
//				}, 300);
			})
		}
		$scope.init_data();
		$scope.delete_invoice = function(id){
			console.log(id);	
			Receipt.invoice_delete(id,function(data){
				if(data.success==true){
					GoDialog.toast('删除成功');
					$scope.init_data();
				}
				else
				GoDialog.toast('删除失败');
				
			})
		}
		$scope.set_default = function(id){
			Receipt.invoice_default(id,function(data){
				if(data.success==true){
					GoDialog.toast('设置成功');
					$scope.init_data();
				}else
				GoDialog.toast('设置失败');
			})
		}
		$scope.isLoad = false; //可以加载
		//画面加载
		$scope.$on('$ionicView.afterEnter', function() {
			//动态设置高度
			var all = $window.innerHeight;
			//计算滚动条
			$scope.myObj = {
				"height": all - 44 + "px"
			};
		}, false);
	
		//下拉刷新 判断哪个模块进行刷新
		$scope.doRefresh = function() {
			$timeout(function() {
				$scope.$broadcast('scroll.refreshComplete');
			}, 1000);
		};
		//加载更多
		$scope.doRefreshMore = function() {
			$timeout(function() {
				$scope.$broadcast('scroll.infiniteScrollComplete');
			}, 1000);
		};
        
        //页面跳转
        $scope.onshow_add = function(id){
        	GoPage.go_states("t-address-add-fp",{id:id});
        }
	}

	controller.$inject = ['$scope', 'Receipt', '$window', '$timeout','GoPage','GoDialog'];
	
	return app.registerController("receiptctrl",controller);
});